package com.wasai.service;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wasai.dao.PromotionDAO;
import com.wasai.domain.Promotion;

@Service
@Transactional(readOnly = true)
public class PromotionService {

	@Resource
	PromotionDAO promotionDAO;

	public List<Promotion> getPromotions(String source) {
		final DetachedCriteria dc = DetachedCriteria.forClass(Promotion.class);
		if ((source != null) && (source.trim().length() > 0)) {
			dc.add(Restrictions.eq("source", source));
		}
		return promotionDAO.findByCriteria(dc, -1, -1,
				new Order[] { Order.desc("validDate") });
	}

}
